package com.digdes.calendar.gwt.client.widget;

import com.digdes.calendar.gwt.client.dto.PlaceDTOImpl;
import com.digdes.calendar.gwt.client.service.CalendarService;
import com.digdes.calendar.gwt.client.service.CalendarServiceAsync;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.*;


/**
 * User: Sulo
 * Date: 08.06.12
 * Time: 2:32
 */
public class CreatePlace extends DialogBox{
    
    
    public CreatePlace(){

        VerticalPanel vp = new VerticalPanel();
        HorizontalPanel hp = new HorizontalPanel();

        final TextBox textBox = new TextBox();
        
        textBox.setSize("200px","30px");


        Button create = new Button("Создать");
        Button close = new Button("Отмена");

        create.setSize("100px", "30px");
        close.setSize("100px", "30px");
        

        close.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent clickEvent) {
                    CreatePlace.this.hide();
            }
        })      ;

        create.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent clickEvent) {
                PlaceDTOImpl placeDTO = new PlaceDTOImpl();
                placeDTO.setAddress(textBox.getText());
                final CalendarServiceAsync calendarservice = GWT.create(CalendarService.class);

                calendarservice.addPlace(placeDTO, new AsyncCallback<String>() {
                    @Override
                    public void onFailure(Throwable throwable) {
                        
                    }

                    @Override
                    public void onSuccess(String s) {
                        Window.alert("Success");
                    
                        
                    
                    }
                });



            }
        })      ;

        
        vp.add(new HTML("Введите адрес:"));
        vp.add(textBox);
        hp.add(create);
        hp.add(close);
        vp.add(hp);
        setWidget(vp);
        
        
        
        
    }
    public void show(){

        super.show();
    }
}
